package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.domain.WxGame;
import com.ruoyi.service.IWxGameService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 比赛Controller
 * 
 * @author ruoyi
 * @date 2022-03-27
 */
@RestController
@RequestMapping("/game/game")
public class WxGameController extends BaseController
{
    @Autowired
    private IWxGameService wxGameService;

    /**
     * 查询比赛列表
     */
    @PreAuthorize("@ss.hasPermi('game:game:list')")
    @GetMapping("/list")
    public TableDataInfo list(WxGame wxGame)
    {
        startPage();
        List<WxGame> list = wxGameService.selectWxGameList(wxGame);
        return getDataTable(list);
    }

    /**
     * 导出比赛列表
     */
    @PreAuthorize("@ss.hasPermi('game:game:export')")
    @Log(title = "比赛", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WxGame wxGame)
    {
        List<WxGame> list = wxGameService.selectWxGameList(wxGame);
        ExcelUtil<WxGame> util = new ExcelUtil<WxGame>(WxGame.class);
        util.exportExcel(response, list, "比赛数据");
    }

    /**
     * 获取比赛详细信息
     */
    @PreAuthorize("@ss.hasPermi('game:game:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(wxGameService.selectWxGameById(id));
    }

    /**
     * 新增比赛
     */
    @PreAuthorize("@ss.hasPermi('game:game:add')")
    @Log(title = "比赛", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WxGame wxGame)
    {
        return toAjax(wxGameService.insertWxGame(wxGame));
    }

    /**
     * 修改比赛
     */
    @PreAuthorize("@ss.hasPermi('game:game:edit')")
    @Log(title = "比赛", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WxGame wxGame)
    {
        return toAjax(wxGameService.updateWxGame(wxGame));
    }

    /**
     * 删除比赛
     */
    @PreAuthorize("@ss.hasPermi('game:game:remove')")
    @Log(title = "比赛", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(wxGameService.deleteWxGameByIds(ids));
    }
}
